<script type="text/html" template lay-done="layui.data.sendParams(d.params)">
  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a><cite>渠道管理</cite></a>
      <a><cite>查看渠道码</cite></a>
    </div>
  </div>

  <div class="layui-card">
    <div class="layui-card-header"><b>渠道信息</b></div>
    <div class="layui-card-body">
      <div>渠道名称：{{d.params.name}}</div>
      <div>创建时间：{{d.params.created_at}}</div>
    </div>
  </div>
  <div class="layui-card">
    <div class="layui-card-header"><b>渠道码</b></div>
    <div class="layui-card-body">
      <div>渠道码：
        <span id="copyuuidtext">{{d.params.uuid}}</span>
        <a style="color:cornflowerblue;margin-left:10px;" id="copyuuid" href="javascript:void(0)">复制</a>
      </div>
      <div>渠道专属链接：
        <span id="copyurltext">{{d.params.channel_url}}</span>
        <a style="color:cornflowerblue;margin-left:10px;" id="copyurl" href="javascript:void(0)">复制</a>
      </div>
      <div>渠道二维码：
        <img src="{{d.params.qrcode}}" alt="">
        <a style="color:cornflowerblue;margin-left:10px;" download="渠道码" id="downloadqrcode" href="{{d.params.qrcode}}">下载</a>
      </div>
    </div>
    <div>注：可通过以上任意方式邀请用户，三种形式均会记录和统计该渠道产生的用户与交易数据</div>
  </div>
</script>

<script>
  layui.data.sendParams = function (obj) {
    layui.use([], function () {
      var $ = layui.$
        , layer = layui.layer

      $(document).on('click', '#copyuuid', function () {
        var value = document.getElementById('copyuuidtext').innerText;
        var textarea = document.createElement('textarea');
        document.body.appendChild(textarea);
        // 隐藏此输入框
        textarea.style.position = 'absolute';
        textarea.style.clip = 'rect(0 0 0 0)';
        // 赋值
        textarea.value = value;
        // 选中
        textarea.select();
        // 复制
        document.execCommand('copy', true);

        layer.alert('复制成功');
      });

      $(document).on('click', '#copyurl', function () {
        var value = document.getElementById('copyurltext').innerText;
        var textarea = document.createElement('textarea');
        document.body.appendChild(textarea);
        // 隐藏此输入框
        textarea.style.position = 'absolute';
        textarea.style.clip = 'rect(0 0 0 0)';
        // 赋值
        textarea.value = value;
        // 选中
        textarea.select();
        // 复制
        document.execCommand('copy', true);

        layer.alert('复制成功');
      });
    });
  }
</script>
